#include "MyMessageBox.h"

MyMessageBox::MyMessageBox(QWidget *parent, const QString &title, const QString &mess) : QDialog(parent) {
    setWindowTitle(title);
    label = new QLabel(this);
    label->setText(mess);
    label->setAlignment(Qt::AlignTop);
    label->setWordWrap(true);
    scroll = new QScrollArea(this);
    scroll->setWidget(label);
    scroll->setWidgetResizable(true);
    okButton = new QPushButton(this);
    connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
    okButton->setText("OK");
/*
    layout = new QGridLayout(this);
    layout->addWidget(scroll, 0, 1, 1, 1, Qt::AlignTop);
    layout->addWidget(okButton, 0, 1, 1, 1, Qt::AlignBottom);
*/
    layout = new QVBoxLayout;
    layout->addWidget(scroll, 0, 0);
    layout->addWidget(okButton, 0, 0);
    setLayout(layout);
}

void MyMessageBox::warning(QWidget *parent, const QString &title, const QString &mess) {
    setWindowTitle(title);
    label = new QLabel(this);
    label->setText(mess);
    scroll = new QScrollArea(this);
    scroll->setGeometry(QRect(10, 20, 280, 100));
    scroll->setWidget(label);
    scroll->setWidgetResizable(true);
    okButton = new QPushButton(this);
    connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
    okButton->setGeometry(QRect(10, 130, 100, 20));
    okButton->setText("OK");
    resize(300,160);
    show();
}

void MyMessageBox::about(QWidget *parent, const QString &title, const QString &mess) {
    setWindowTitle(title);
    label = new QLabel(this);
    label->setText(mess);
    scroll = new QScrollArea(this);
    scroll->setGeometry(QRect(10, 20, 280, 100));
    scroll->setWidget(label);
    scroll->setWidgetResizable(true);
    okButton = new QPushButton(this);
    connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
    okButton->setGeometry(QRect(10, 130, 100, 20));
    okButton->setText("OK");
    resize(300,160);
    show();
}

void MyMessageBox::critical(QWidget *parent, const QString &title, const QString &mess) {
    setWindowTitle(title);
    label = new QLabel(this);
    label->setText(mess);
    scroll = new QScrollArea(this);
    scroll->setGeometry(QRect(10, 20, 280, 100));
    scroll->setWidget(label);
    scroll->setWidgetResizable(true);
    okButton = new QPushButton(this);
    connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
    okButton->setGeometry(QRect(10, 130, 100, 20));
    okButton->setText("OK");
    resize(300,160);
    show();
}

void MyMessageBox::information(QWidget *parent, const QString &title, const QString &mess) {
    setWindowTitle(title);
    label = new QLabel(this);
    label->setText(mess);
    scroll = new QScrollArea(this);
    scroll->setGeometry(QRect(10, 20, 280, 100));
    scroll->setWidget(label);
    scroll->setWidgetResizable(true);
    okButton = new QPushButton(this);
    connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
    okButton->setGeometry(QRect(10, 130, 100, 20));
    okButton->setText("OK");
    resize(300,160);
    show();
}
